#include "BBGeometry.h"

/************************************************************************/
//BBPoint
BBPoint::BBPoint( void )
{
	setPoint(0.0f,0.0f);
}

BBPoint::BBPoint( float x, float y )
{
	setPoint(x,y);
}

BBPoint::BBPoint( const BBPoint& other )
{
	setPoint(other.x,other.y);
}

BBPoint& BBPoint::operator=( const BBPoint& other )
{
	setPoint(other.x, other.y);
	return *this;
}

void BBPoint::setPoint( float x, float y )
{
	this->x = x;
	this->y = y;
}

bool BBPoint::equals( const BBPoint& target ) const
{
	return ((this->x == target.x) && (this->y == target.y));
}

BBPoint::~BBPoint( void )
{

}
/************************************************************************/
//BBSize
BBSize::BBSize( void )
{
	setSize(0.0f,0.0f);
}

BBSize::BBSize( float width,float height )
{
	setSize(width,height);
}

BBSize::BBSize( const BBSize& other )
{
	setSize(other.width,other.height);
}

BBSize::~BBSize( void )
{
	setSize(0.0f,0.0f);
}

BBSize& BBSize::operator=( const BBSize& other )
{
	setSize(other.width,other.height);
	return *this;
}

void BBSize::setSize( float width,float heigth )
{
	this->width = width;
	this->height = heigth;
}

bool BBSize::equals( const BBSize& size ) const
{
	return ((this->width == size.width) && (this->height == size.height));
}

/************************************************************************/
//BBRectange

BBRectange::BBRectange( void )
{
	setRect(0.0f,0.0f,0.0f,0.0f);
}

BBRectange::BBRectange( float x, float y, float width, float height )
{
	setRect(x,y,width,height);
}

BBRectange::BBRectange( const BBRectange& other )
{
	setRect(other.origin.x,other.origin.y,other.size.width,other.size.height);
}

BBRectange::~BBRectange(void)
{
	setRect(0.0f,0.0f,0.0f,0.0f);
}

BBRectange& BBRectange::operator=( const BBRectange& other )
{
	setRect(other.origin.x,other.origin.y,other.size.width,other.size.height);
	return *this;
}

void BBRectange::setRect( float x, float y, float width, float height )
{
	this->origin.setPoint(x,y);
	this->size.setSize(width,height);
}

float BBRectange::getMinX() const
{
	return origin.x;
}

float BBRectange::getMidX() const
{
	return (origin.x + size.width *.5);
}

float BBRectange::getMaxX() const
{
	return origin.x + size.width;
}

float BBRectange::getMinY() const
{
	return origin.y;
}

float BBRectange::getMidY() const
{
	return origin.y + size.height * 0.5;
}

float BBRectange::getMaxY() const
{
	return origin.y + size.height;
}

bool BBRectange::equals( const BBRectange& rect ) const
{
	return (origin.equals(rect.origin) && size.equals(rect.size));
}

bool BBRectange::containsPoint( const BBRectange& point ) const
{
	return (point.origin.x >=getMinX() && point.origin.x <=getMaxX() && point.origin.y >=getMinX() && point.origin.y <=getMaxY());
}

bool BBRectange::intersectsRect( const BBRectange& rect ) const
{
	return !(getMaxX() < rect.getMinX() || 
		rect.getMaxX() < getMinX() ||
		getMaxY() < rect.getMinY() ||
		rect.getMaxY() < getMinY());
}
